from socket import *
from time import ctime

HOST = ''
PORT = 9998
BUFSIE = 1024
ADDR = (HOST, PORT)

tcpSerCock = socket(AF_INET, SOCK_STREAM)
tcpSerCock.bind(ADDR)
tcpSerCock.listen(5)

while True:
    print('[+]waiting for connection...')
    tcpCliSock, addr = tcpSerCock.accept()
    print('[+]connection from:', addr)

    while True:
        data = tcpCliSock.recv(BUFSIE)
        if not data:
            break
        tcpCliSock.send('[%s]%s' % (ctime(), data))
        tcpCliSock.close()
    tcpSerCock.close()
